const mysql = require('mysql');
const connent = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'employees'
});

connent.connect((error)=>{
    if(error){
        console.log('连接失败', error);
    }else{
        console.log('连接成功');
    }
});

//查询语句
let str1 = "SELECT from_date, to_date from dept_manager where to_date between '1990-01-01' and '2024-01-01'"
let str4 = "select * from dept_manager where dept_no = 'd001'";
let str5 = "select * from titles where title like '%A%'";
let str6 = "SELECT * FROM dept_manager Right JOIN employees on dept_manager.dept_no = 'd010'";
let str7 = "SELECT * FROM dept_manager Left JOIN employees on dept_manager.dept_no = 'd010'";
let str8 = "SELECT * FROM accouts inner JOIN user on accouts.emp_no = employees.emp_no"


//添加
let add1 = "insert into titles (title) values ('张三')"

//删除
let del1 = "delete from titles where title id = 1;"

//更新
let up1 = "UPDATE titles as a Left JOIN employees as b ON a.emp_no = b.emp_no SET a.title = '中文标题' where a.title = null";


connent.query(up1, (error, result)=>{
    if(error){
        console.log('查询失败', error);
    }else{
        console.log('查询成功', result);
    }
})
// connent.query(`select * from user`, (error, result)=>{
//     if(error){
//         console.log('查询失败', error);
//     }else{
//         console.log('查询成功', result);
//     }
// });
//
// module.exports = connent;